{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9bf0dbd6",
   "metadata": {},
   "source": [
    "#### Create your own `Audiobook` 🎧 🚀 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9ec08fba",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pdfplumber as pp\n",
    "from gtts import gTTS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71b77cfa-30a4-48c3-8433-115925f6d5e2",
   "metadata": {},
   "source": [
    "##### 1️⃣ Extract text from pdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "605fc3ed-cbb8-48c6-9776-b701eba4cb5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "pdf_text = ''\n",
    "\n",
    "with pp.open('attention_is_all_you_need.pdf') as pdf:\n",
    "    for page in pdf.pages:\n",
    "        pdf_text += page.extract_text()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db3e6277-79b5-4b13-bcc4-3cb43b621fd1",
   "metadata": {},
   "source": [
    "##### 2️⃣ Convert extracted text to speech"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cdda44ac-8a0f-473e-abe2-29d4409dc2de",
   "metadata": {},
   "outputs": [],
   "source": [
    "tts = gTTS(text=pdf_text, lang='en')\n",
    "tts.save('audio_book.mp3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df9e8880-a53c-4f00-8184-4106db3bf567",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_twitter",
   "language": "python",
   "name": "env_twitter"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
